﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StackExchange.Profiling;

namespace D.Util.UtilMiniProfiler
{
    public static class MiniProfilerUtil
    {
        /// <summary>
        /// .NET性能分析 
        /// MiniProfiler.AspNetCore.Mvc
        /// </summary>
        /// <param name="services"></param>
        public static void AddMiniProfilerStartup(this IServiceCollection services)
        {
            services.AddMiniProfiler(o =>
            {
                // 配置了MiniProfiler的路由基础路径，默认是/mini-profiler-resources,使用域名:端口/profiler/results来访问分析报告
                o.RouteBasePath = "/profiler";
            });
        }

        public static void UseMiniProfilerStartup(this WebApplication app)
        {
            app.UseMiniProfiler();
        }

        /// <summary>
        /// 输出内容
        /// </summary>
        /// <param name="type"></param>
        /// <param name="info"></param>
        public static void PrintToMiniProfiler(string type, string info)
        {
            // 更细粒度的对报告内容进行分类
            using (MiniProfiler.Current.CustomTiming(type, info)) ;
        }
    }
}
